/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.meanzoft.minecraft_clone.effect;

import org.meanzoft.minecraft_clone.Game;
import org.meanzoft.m3d.resource.ResourceManager;
import org.meanzoft.m3d.scene.Renderable;
import org.meanzoft.m3d.scene.SceneNode;
import static org.lwjgl.opengl.GL11.*;
/**
 *
 * @author Meanz
 */
public class SkyBox extends SceneNode implements Renderable {

    public void render() {
        // Store the current matrix
        glPushMatrix();
        glScalef(0.05f, 0.05f, 0.05f);
        Game.getGame().gameCamera.updateSkyBoxRender();

        // Enable/Disable features
        glPushAttrib(GL_ENABLE_BIT);
        glEnable(GL_TEXTURE_2D);
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);
        glDisable(GL_BLEND);

        // Just in case we set all vertices to white.
        glColor4f(1, 1, 1, 1);

        // Render the front quad
        ResourceManager.getManager().getTexture("sky_0").bind();
        glBegin(GL_QUADS);
        glTexCoord2f(0, 0);
        glVertex3f(0.5f, -0.5f, -0.5f);
        glTexCoord2f(1, 0);
        glVertex3f(-0.5f, -0.5f, -0.5f);
        glTexCoord2f(1, 1);
        glVertex3f(-0.5f, 0.5f, -0.5f);
        glTexCoord2f(0, 1);
        glVertex3f(0.5f, 0.5f, -0.5f);
        glEnd();

        // Render the left quad
        ResourceManager.getManager().getTexture("sky_1").bind();
        glBegin(GL_QUADS);
        glTexCoord2f(0, 0);
        glVertex3f(0.5f, -0.5f, 0.5f);
        glTexCoord2f(1, 0);
        glVertex3f(0.5f, -0.5f, -0.5f);
        glTexCoord2f(1, 1);
        glVertex3f(0.5f, 0.5f, -0.5f);
        glTexCoord2f(0, 1);
        glVertex3f(0.5f, 0.5f, 0.5f);
        glEnd();

        // Render the back quad
        ResourceManager.getManager().getTexture("sky_2").bind();
        glBegin(GL_QUADS);
        glTexCoord2f(0, 0);
        glVertex3f(-0.5f, -0.5f, 0.5f);
        glTexCoord2f(1, 0);
        glVertex3f(0.5f, -0.5f, 0.5f);
        glTexCoord2f(1, 1);
        glVertex3f(0.5f, 0.5f, 0.5f);
        glTexCoord2f(0, 1);
        glVertex3f(-0.5f, 0.5f, 0.5f);

        glEnd();

        // Render the right quad
        ResourceManager.getManager().getTexture("sky_3").bind();
        glBegin(GL_QUADS);
        glTexCoord2f(0, 0);
        glVertex3f(-0.5f, -0.5f, -0.5f);
        glTexCoord2f(1, 0);
        glVertex3f(-0.5f, -0.5f, 0.5f);
        glTexCoord2f(1, 1);
        glVertex3f(-0.5f, 0.5f, 0.5f);
        glTexCoord2f(0, 1);
        glVertex3f(-0.5f, 0.5f, -0.5f);
        glEnd();

        // Render the top quad
        ResourceManager.getManager().getTexture("sky_4").bind();
        glBegin(GL_QUADS);
        glTexCoord2f(0, 1);
        glVertex3f(-0.5f, 0.5f, -0.5f);
        glTexCoord2f(0, 0);
        glVertex3f(-0.5f, 0.5f, 0.5f);
        glTexCoord2f(1, 0);
        glVertex3f(0.5f, 0.5f, 0.5f);
        glTexCoord2f(1, 1);
        glVertex3f(0.5f, 0.5f, -0.5f);
        glEnd();

        // Render the bottom quad
        ResourceManager.getManager().getTexture("sky_5").bind();
        glBegin(GL_QUADS);
        glTexCoord2f(0, 0);
        glVertex3f(-0.5f, -0.5f, -0.5f);
        glTexCoord2f(0, 1);
        glVertex3f(-0.5f, -0.5f, 0.5f);
        glTexCoord2f(1, 1);
        glVertex3f(0.5f, -0.5f, 0.5f);
        glTexCoord2f(1, 0);
        glVertex3f(0.5f, -0.5f, -0.5f);
        glEnd();

        // Restore enable bits and matrix
        glPopAttrib();
        glPopMatrix();
    }
}